import java.io.*;
import java.net.*;


public class HttpRuServer {

    // Declaration section:
    // declare a server socket and a client socket for the server
    // declare an input and an output stream

    static Socket clientSocket = null;
    static ServerSocket serverSocket = null;
    static ClientThread clientThread = null;

    // This chat server can accept up to 10 clients' connections


    public static void main(String args[]) {

        if (args.length == 0) {
            System.out.println("Usage : tcp <portnumber>");
            return;
        }


        int port_number = Integer.valueOf(args[1]);
        try {
            serverSocket = new ServerSocket(port_number);
        }
        catch (IOException e) {
            System.out.println(e);
        }
        try {
            if (args[0].equalsIgnoreCase("tcp")) {

                while (true) {

                    clientSocket = serverSocket.accept();           //accept connection
                    clientThread = new ClientThread(clientSocket);  //start thread
                }
            } else if (args[0].equalsIgnoreCase("udp")) {

                UDPServer udpServer = new UDPServer(port_number);
                udpServer.run();

            } else {
                System.out.println("You have entered wrong input: use either tcp or udp");
            }

        }

        catch (IOException e) {
            System.out.println(e);
        }
        catch (Exception ex) {
            System.out.println(ex);
        }


    }


}
